-
Notifications
You must be signed in to change notification settings - Fork 31
FIX: Decode Raw UTF-16 data from Conn.getinfo() #340
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
📊 Code Coverage Report
Diff CoverageDiff: main...HEAD, staged and unstaged changes
Summary
📋 Files Needing Attention📉 Files with overall lowest coverage (click to expand)mssql_python.pybind.logger_bridge.hpp: 58.8%
mssql_python.pybind.logger_bridge.cpp: 59.2%
mssql_python.pybind.ddbc_bindings.cpp: 66.2%
mssql_python.row.py: 66.2%
mssql_python.helpers.py: 67.5%
mssql_python.pybind.connection.connection.cpp: 73.6%
mssql_python.ddbc_bindings.py: 79.6%
mssql_python.connection.py: 83.9%
mssql_python.cursor.py: 84.3%
mssql_python.__init__.py: 84.9%🔗 Quick Links
|
…ub.com/microsoft/mssql-python into bewithgaurav/fix-conninfo-utf-decoding
… bewithgaurav/fix-conninfo-utf-decoding
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
This pull request fixes a UTF-16 encoding bug in the getinfo() method that was causing null bytes to appear in string values returned from SQL Server. The fix implements a proper encoding fallback mechanism (UTF-16LE → UTF-8) to handle ODBC's wide-character API responses, adds comprehensive test coverage for the encoding scenarios, and removes redundant DLL copying logic from the Windows build script.
Key Changes:
- Replaced single UTF-8 decoding attempt with a multi-encoding fallback strategy (UTF-16LE first, then UTF-8)
- Added four new test cases covering UTF-16 decoding success, UTF-8 fallback, encoding failure, and null byte detection
- Removed obsolete
msvcp140.dllredistribution logic from the build script
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
mssql_python/connection.py |
Implements UTF-16LE decoding with UTF-8 fallback in getinfo() method for proper ODBC string handling |
tests/test_003_connection.py |
Adds comprehensive test coverage for UTF-16 encoding scenarios including primary path, fallback path, and failure cases |
mssql_python/pybind/build.bat |
Removes redundant Visual C++ redistributable DLL copying logic |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
… bewithgaurav/fix-conninfo-utf-decoding
Work Item / Issue Reference
Summary
This pull request introduces improvements to the handling of string encoding in the
getinfomethod for SQL Server connections, adds support for profiling builds in the Windows build script, and enhances test coverage for string decoding. The most important changes are grouped below:String Decoding Improvements
getinfomethod inconnection.pynow attempts to decode string results from SQL Server using multiple encodings in order: UTF-16LE (Windows default), UTF-8, and Latin-1. This improves robustness when handling driver responses and avoids silent data corruption by returningNoneif all decoding attempts fail.Test Coverage
test_getinfo_string_encoding_utf16intest_003_connection.pyto verify that string values returned bygetinfoare properly decoded from UTF-16, contain no null bytes, and are non-empty, helping catch encoding mismatches early.Build Script Cleanup
build.batrelated to copying themsvcp140.dllredistributable, simplifying the post-build process.